package com.sogoodsoft.service.app;

import java.util.List;

import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.sogoodsoft.dao.app.SysClassDao;
import com.sogoodsoft.dao.common.CommonHibernateDao;
import com.sogoodsoft.entity.app.SysClass;
import com.sogoodsoft.service.common.AbstractService;


@Component
@Transactional
public class SysClassService extends AbstractService<SysClass,Long> {

	
	protected SysClassDao dao;
	
	
	public SysClass getFirst(){
		Query query = dao.createQuery("from SysClass order by id asc");
		query.setMaxResults(1);
		return (SysClass)query.list().get(0);
	}
	
	@SuppressWarnings("unchecked")
	public SysClass getByCode(String code){
		Query query = dao.createQuery("from SysClass where code=?",code);
		query.setMaxResults(1);
		List<SysClass> list = query.list();
		if(list.size()>0){
			return (SysClass)query.list().get(0);
		}else{
			return null;
		}
		
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public CommonHibernateDao getDao(){
		return dao;
	}
	
	@Autowired
	public void setDao(SysClassDao dao) {
		this.dao = dao;
	}


	
}
